﻿using Nett;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace GKScoreQueryHelper
{
    public class CustomConfiguration
    {
        private readonly string fileName;
        public CustomConfiguration(string fn)
        {
            fileName = fn;
            Init();
        }

        public void Init()
        {
            using FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            table = Toml.ReadStream(fs);
            _Server_URL = Get<string>("server", "url");
            _Server_Headless = Get<bool>("server", "headless");
            _Page_gkbmh = Get<string>("page", "gkbmh");
            _Page_sfzh = Get<string>("page", "sfzh");
            _Page_valicode = Get<string>("page", "valicode");
            _Page_yzm = Get<string>("page", "yzm");
            _Page_basetable = Get<string>("page", "basetable");
            _Page_cjtable = Get<string>("page", "cjtable");
            _Page_submit = Get<string>("page", "submit");
            _Page_retry = Get<string>("page", "retry");
            _Page_next = Get<string>("page", "next");
            _File_template = Get<string>("file", "templateFile");
            _File_result = Get<string>("file", "resultFile");
            _File_Error = Get<string>("file", "errorFile");
            _Runtime_debug = Get<bool>("runtime", "debug");
            _Runtime_debug_folder = Get<string>("runtime", "debug_folder");
            _Work_folder = Get<string>("runtime", "work_folder");
            _Sp_work_folder = Get<string>("runtime", "sp_work_folder");
            _Format_fields = Get<string>("format", "fields");
            _Page_verify = Get<string>("page", "verify");
            _Page_verifyimg = Get<string>("page", "verifyimg");
            _Server_channel = Get<string>("server", "channel");
            _Server_chromiumSandbox = Get<bool>("server", "chromiumSandbox");
            _Page_yzm_length = Get<int>("page", "yzm_length");
            _Runtime_max_retry_times = Get<int>("runtime", "max_retry_times");
            _Runtime_captcha_type = Get<int>("runtime", "captcha_type");
            _Runtime_task_type = Get<int>("runtime", "task_type");
        }



        private TomlTable table;
        private T Get<T>(string sectionName, string propertyName)
        {
            return table.Get<TomlTable>(sectionName).Get<T>(propertyName);
        }

 

        private string _Server_URL;
        public string Server_URL => _Server_URL;


        private bool _Server_Headless;
        public bool Server_Headless => _Server_Headless;

        private string _Page_gkbmh;
        public string Page_gkbmh => _Page_gkbmh;

        private string _Page_sfzh;
        public string Page_sfzh => _Page_sfzh;

        private string _Page_valicode;
        public string Page_valicode => _Page_valicode;
        private string _Page_yzm;
        public string Page_yzm => _Page_yzm;
        private string _Page_basetable;
        public string Page_basetable => _Page_basetable;
        private string _Page_cjtable;
        public string Page_cjtable => _Page_cjtable;

        private string _Page_submit;
        public string Page_submit => _Page_submit;

        private string _Page_retry;
        public string Page_retry => _Page_retry;

        private string _Page_next;
        public string Page_next => _Page_next;

        private string _File_template;
        public string File_template => _File_template;
        private string _File_result;
        public string File_result => _File_result;

        private string _File_Error;
        public string File_error => _File_Error;

        private bool _Runtime_debug;
        public bool Runtime_debug => _Runtime_debug;

        private string _Runtime_debug_folder;
        public string Runtime_debug_folder => _Runtime_debug_folder;

        private string _Work_folder;
        public string Work_folder => _Work_folder;
        private string _Sp_work_folder;
        public string Sp_work_folder => _Sp_work_folder;
        private string _Format_fields;
        public string Format_fields => _Format_fields;
        private string _Page_verify;
        public string Page_verify =>_Page_verify; 
        private string _Page_verifyimg;
        public string Page_verifyimg => _Page_verifyimg;
        private string _Server_channel;
        public string Server_channel => _Server_channel;
        private bool _Server_chromiumSandbox;
        public bool Server_chromiumSandbox =>_Server_chromiumSandbox;
        private int _Page_yzm_length;
        public int Page_yzm_length => _Page_yzm_length;
        private int _Runtime_max_retry_times;
        public int Runtime_max_retry_times => _Runtime_max_retry_times;

        private int _Runtime_captcha_type;
        public int Runtime_captcha_type => _Runtime_captcha_type;
        private int _Runtime_task_type;
        public int Runtime_task_type => _Runtime_task_type;

        
    }
}
